//+------------------------------------------------------------------+ //| Brainwashing #1c.mq4 | //| code by Alex.Piech.FinGeR | //| http://www.forex-tsd.com | //| buletproofing open/close/modify orders | //| and code cleanup by Nick Bilak | //| | //| 01.11.2005 #1c - i_Trend add-on by Nick Bilak | //| 20.10.2005 Brainwashing #1a by Alex.Piech.FinGeR | //| BIG Thanks newdigital by forex-tsd.com | //| look please last Line !!!! | //+------------------------------------------------------------------+ #include #property copyright "Alex.Piech.FinGeR" #property link "http://www.forex-tsd.com" extern int MAGIC=20051021; extern string PARAMETERS_TRADE = "PARAMETERS TRADE"; extern int SLIPPAGE = 3; extern double Lots = 0.1; extern int StopLoss = 10; extern int TakeProfit = 80; extern bool OnlyEnterOnFullBars = true; extern bool OnlyExitOnFullBars = true; extern bool UseHourTrade = True; extern int FromHourTrade = 9; extern int ToHourTrade = 21; extern bool useCloseTradeRules = False; extern bool useProfitTrailing = True; extern int TrailingStop = 20; extern int TrailingStep = 3; extern string PARAMETERS_INDICATOR_ONE = "PriceChannel_Stop_v1"; extern int ChannelPeriod = 9; extern double Risk = 0.3; extern int Nbars = 200; extern string PARAMETERS_INDICATOR_TWO = "Price Channel"; extern int ChannelPeriod2=14; extern int Shift=0; extern string PARAMETERS_INDICATOR_3 = "i_Trend"; extern int Bands_Period=20; extern int Bands_Deviation=2; extern int Power_Period=13; extern int CountBars=300; extern bool ItrendFilter=true; extern double ItrendLevel=0.0; //iTrend line must be above this level extern string PARAMETERS_EXPERT = "PARAMETERS EXPERT"; extern bool UseOneAccount = False; extern int NumberAccount = 0815; extern string Name_Expert = "Brainwashing #1c"; extern bool UseSound = False; extern string NameFileSound = "expert.wav"; extern color clOpenBuy = LightBlue; extern color clOpenSell = LightCoral; extern color clModifyBuy = Aqua; extern color clModifySell = Tomato; extern color clCloseBuy = Blue; extern color clCloseSell = Red; int prevBar,ttime; bool bx=False; bool sx=False; void SetArrow(datetime t, double p, int k, color c) { ObjectSet("Arrow", OBJPROP_TIME1 , t); ObjectSet("Arrow", OBJPROP_PRICE1 , p); ObjectSet("Arrow", OBJPROP_ARROWCODE, k); ObjectSet("Arrow", OBJPROP_COLOR , c); } void deinit() { //Comment(""); } void start() { //---- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; SetArrow(Time[0],Low[0]-5*Point,241,Gold); bx=False; sx=False; CheckForOpen(); if (useCloseTradeRules) CheckForClose2(); if (useProfitTrailing) TrailingPositions(); } void CheckForOpen() { bx=False; sx=False; double ldStop=0, ldTake=0; if (OnlyEnterOnFullBars) { if (Volume[0]>1) return(0); else int lookupidx= 1; // look at the values of the previous bar (recently completed bar) } else { lookupidx= 0; } if (OnlyExitOnFullBars) { if (Volume[0]>1) return(0); else int lookupidx2= 1; // look at the values of the previous bar (recently completed bar) } else { lookupidx2= 0; } double Buy=iCustom(NULL, 0, "PriceChannel_Stop_v1",ChannelPeriod,Risk,1,1,Nbars,0,lookupidx); double Buy1=iCustom(NULL, 0, "PriceChannel_Stop_v1",ChannelPeriod,Risk,1,1,Nbars,3,lookupidx); double Sell=iCustom(NULL, 0, "PriceChannel_Stop_v1",ChannelPeriod,Risk,1,1,Nbars,1,lookupidx); double Sell1=iCustom(NULL, 0, "PriceChannel_Stop_v1",ChannelPeriod,Risk,1,1,Nbars,2,lookupidx); double xBuy=iCustom(NULL, 0, "PriceChannel_Stop_v1",ChannelPeriod,Risk,1,1,Nbars,0,lookupidx2); double xBuy1=iCustom(NULL, 0, "PriceChannel_Stop_v1",ChannelPeriod,Risk,1,1,Nbars,3,lookupidx2); double xSell=iCustom(NULL, 0, "PriceChannel_Stop_v1",ChannelPeriod,Risk,1,1,Nbars,1,lookupidx2); double xSell1=iCustom(NULL, 0, "PriceChannel_Stop_v1",ChannelPeriod,Risk,1,1,Nbars,2,lookupidx2); double iTredn1=iCustom(NULL,0,"i_Trend",0,0,0,Bands_Period,Bands_Deviation,Power_Period,300,0,lookupidx); //green double iTredn2=iCustom(NULL,0,"i_Trend",0,0,0,Bands_Period,Bands_Deviation,Power_Period,300,1,lookupidx); //red if (xSell==-1 && xSell1>-1 && ((ItrendFilter && iTredn2>ItrendLevel && iTredn2>iTredn1) ||!ItrendFilter) //iTrend filter ) { Print("dgdfgdgsdgsdgsdgdgdfhgdfhgdfhgdfghdfhdfhdfghdfhdfhgs"); sx=True; CheckForClose(); } if (xBuy==-1 && xBuy1>-1 && ((ItrendFilter && iTredn1>ItrendLevel && iTredn1>iTredn2) ||!ItrendFilter) //iTrend filter ) { Print("dgdfgdgsdgsdgsdgdgsghfhdfghdfhgdfhdfhdfhdfhdfhd"); bx=True; CheckForClose(); } if (!ExistPosition() && ttime!=Time[0]) { if (Sell==-1 && Sell1>-1 && ((ItrendFilter && iTredn1>ItrendLevel && iTredn1>iTredn2) ||!ItrendFilter) //iTrend filter ) { if (StopLoss!=0) ldStop=Sell1-StopLoss*Point; if (TakeProfit!=0) ldTake=Ask+TakeProfit*Point; SetOrder(OP_BUY, Ask, ldStop, ldTake); ttime=Time[0]; } if (Buy==-1 && Buy1>-1 && ((ItrendFilter && iTredn2>ItrendLevel && iTredn2>iTredn1) ||!ItrendFilter) //iTrend filter ) { if (StopLoss!=0) ldStop=Buy1+StopLoss*Point; if (TakeProfit!=0) ldTake=Bid-TakeProfit*Point; SetOrder(OP_SELL, Bid, ldStop, ldTake); ttime=Time[0]; } } } void CheckForClose() { bool bres; int total=OrdersTotal(); for (int i=0; iToHourTrade) ) return; int res; double prc; color clOpen; string lsComm=GetCommentForOrder(); if (op==OP_BUY) clOpen=clOpenBuy; else clOpen=clOpenSell; res=0; while (res<=0) { RefreshRates(); if (op==OP_BUY) prc=Ask; if (op==OP_SELL) prc=Bid; res=OrderSend(Symbol(),op,Lots,prc,SLIPPAGE,ldStop,ldTake,lsComm,MAGIC,0,clOpen); Sleep(6000); if (res<0) Print("Error opening order : "+op+" - ",ErrorDescription(GetLastError())); } if (UseSound) PlaySound(NameFileSound); } string GetCommentForOrder() { return(Name_Expert); } void TrailingPositions() { int total=OrdersTotal(); for (int i=0; iTrailingStop*Point) { if (OrderStopLoss()TrailingStop*Point) { if (OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*Point || OrderStopLoss()==0) { RefreshRates(); ModifyStopLoss(Ask+TrailingStop*Point, clModifySell); } } } } } } } void CheckForClose2() { bool fs=False; bool fs1=False; bool bres; double high=iCustom(NULL, 0, "Price Channel",ChannelPeriod2,Shift,0,0); double low=iCustom(NULL, 0, "Price Channel",ChannelPeriod2,Shift,1,0); if (Close[0]==low) fs1 = True; if (Close[0]==high) fs = True; int total=OrdersTotal(); for (int i=0; i